<template>
	<div class="app">
		<h1>我是App组件</h1>
		<h3>Grandson给我的玩具:{{toy}}</h3>
		<h3>Child1给我的电脑:{{computer}}</h3>
		<Child1/>
		<br>
		<Child2/>
	</div>
</template>

<script>
	import Child1 from './components/Child1.vue'
	import Child2 from './components/Child2.vue'

	export default {
		name:'App',
		components:{Child1,Child2},
		data() {
			return {
				toy:'',
				computer:''
			}
		},
		mounted(){
			console.log('App')
			//爷爷组件，一旦挂载完毕，马上找到x去绑定事件
			this.$bus.$on('get-toy',(value)=>{
				this.toy = value
			})
			this.$bus.$on('get-computer',(value)=>{
				this.computer = value
			})
		},
		beforeDestroy(){
			this.$bus.$off('haha')
			this.$bus.$off('get-tcomputer')
		}
	}
</script>

<style>
	.app{
		background-color: gray;
		padding: 20px;
	}
</style>